package mysql

import (
	"fmt"
	"database/sql"
	"log"
	_ "github.com/go-sql-driver/mysql"
)

type UserInfo struct {
	Uid uint64
	Name string
	RealName string
}

func OpenDb() {
	defer func() {
		if err := recover(); err != nil {
			log.Println(err)
		}
	}()
	db, err := sql.Open(dbDriver, dbSource)
	if err != nil {
		log.Println(err)
	}

	rs, err := db.Query("SELECT id,user_name, real_name FROM firstp2p_user LIMIT 10")
	if err != nil {
		log.Println(err)
	}

	var record []UserInfo
	for rs.Next() {
		var id uint64 = 0
		var name, realname string = "", ""
		rs.Scan(&id, &name, &realname)
		var row UserInfo = UserInfo{id, name, realname}
		record = append(record, row)
	}
	fmt.Println(record)
}